package main

import "fmt"

type MyError struct {
	Msg string
	File string
	Line int
}

func (e *MyError) Error() string{
	return fmt.Sprintf("%s:%d: %s", e.File, e.Line, e.Msg)
}

func something() error  {
	return &MyError{"Something happend", "errors.go", 16}
}

func main() {
	err := something()

	switch err := err.(type) {
	case nil:
	case *MyError:
		fmt.Println("MyError错误：error occurred on line", err.Line)
	default:
		fmt.Println("default")
	}
}
